package cloud.alibaba.sentinel.handler;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;

/**
 * @auther xfanonymous
 * @create 2024-01-04 10:42
 * Sentinel p3
 * 授权规则，对请求来源设置黑白名单
 * 1. 请求来源处理器转换，实现接口RequestOriginParser和方法parseOrigin()
 * 2. 例如：可以设置serverName为URL的必传参数，在此方法中对?serverName=test设置为黑名单
 */
@Component
public class MyRequestOriginParser implements RequestOriginParser
{
    @Override
    public String parseOrigin(HttpServletRequest request)
    {
        return request.getParameter("serverName");
    }
}